// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  traceUser: true,
  env:'aaa111-9gh9fp5ieac4de5d'
})

const db = cloud.database()
// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  var guanzhu = await db.collection('follow').where({
    _openid: wxContext.OPENID // 填入当前用户 openid
  }).count()
  var fensi = await db.collection('follow').where({
    follow: wxContext.OPENID // 填入当前用户 openid
  }).count()
  var youji = await db.collection('postinfo').where({
    _openid: wxContext.OPENID // 填入当前用户 openid
  }).count()
  var heartAmount = await db.collection('userHeart').where({
    _openid: wxContext.OPENID // 填入当前用户 openid
  }).count()
  return {
    guanzhu: guanzhu.total,
    follow: fensi.total,
    youji: youji.total,
    heartAmount: heartAmount.total
  }
}